#include <iostream>
#include <memory>
#include "SerialPort.h"
#include "DisplayDriver.h"
#include "SystemInfo.h"
#include <unistd.h>
using namespace MC500;
using namespace std;
int main()
{
    
    shared_ptr<SerialPort> uart = SerialPort::Create("COM8");
    int32_t ret = uart->Init(38400L);
    if (ret != MC500_SUCCESS)
    {
        return ret;
    }

    shared_ptr<DisplayDriver> driver = make_shared<DisplayDriver>(uart);
    do{
        DateTime dateTime = SystemInfo::GetInstance()->GetDateTime();
        char buff[32] = {0};
        sprintf(buff,"%04d%02d%02d %02d:%02d:%02d",dateTime.year%10000, dateTime.month%100, dateTime.dayOfMonth%100, dateTime.hour, dateTime.min,dateTime.sec );
        driver->WriteString(0, 0, buff);
        sprintf(buff,"CPU:%d%%    Mem:%d%%",SystemInfo::GetInstance()->GetCPUUsed(), (uint8_t)(SystemInfo::GetInstance()->GetPhyMemUsed()/SystemInfo::GetInstance()->GetPhyMem()));
        driver->WriteString(0, 16, buff);
        driver->Refresh(false);

        cout << "Freshed!" << endl;

       sleep(1);

    }while(1);
    
    return 0;

#if 0
    driver->WriteString(0, 0, "abcTT This is too long too long");
    driver->WriteString(0, 16, "Are you ready?");
    cout << "Full line write finished" << endl;
    driver->print();

    driver->WriteString(0, 34, "abcTT This is too long too long");
    cout << "Combine line write finished" << endl;
    driver->print();

    driver->WriteString(0, 55, "abcTT This is too long too long");
    cout << "Combine line write finished" << endl;
    driver->print();

    driver->Refresh(false);

       

    //uart->Send((const uint8_t *)"00\n", sizeof("00\n"));

    //uint8_t buff[128];

    //uart->Read(buff,sizeof(buff));
#endif

    return 0;
}